<template>
  <a-modal
    title="编辑用户"
    :width="800"
    :mask-closable="false"
    :destroy-on-close="true"
    v-model="visible"
    :footer="null"
  >
    <a-card :bordered="false" class="card_top_padding" style="margin-bottom: 11px">
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="20" style="padding-top: 20px;">
            <a-col :md="8" :sm="24">
              <a-form-item>
                <a-input-search v-model="queryParamSelect.name" placeholder="请输入用户昵称/名称" />
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item>
                <a-input-search v-model="queryParamSelect.phone" placeholder="请输入用户手机号" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <span class="table-page-search-submitButtons" style="margin-bottom:0">
                <a-button style="margin-right: 8px" @click="() => (this.queryParamSelect = {})">重置</a-button>
                <a-button type="primary" @click="onPageSearch">查询</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>

    <s-table ref="table1" size="default" rowKey="key" :columns="columns" :data="loadDataSelect" showPagination="auto">
      <span slot="baseinfo" slot-scope="text, record1">
        <div class="flex">
          <div class="img">
            <img :src="record1.avatar_url" />
          </div>

          <div class="txt">
            <ellipsis :length="20" tooltip>{{ record1.nickname }} </ellipsis>
          </div>
        </div>
      </span>
      <span slot="platform" slot-scope="text">
        <ellipsis v-show="text == '0'" :length="4" tooltip>微信</ellipsis>
        <ellipsis v-show="text == '1'" :length="4" tooltip>支付宝</ellipsis>
        <ellipsis v-show="text == '3'" :length="4" tooltip>手机</ellipsis>
      </span>
      <span slot="time" slot-scope="text, record1">
        <span>{{ record1.created_at | timeFormat }}</span>
      </span>
      <span slot="action" slot-scope="text, record1">
        <a-button type="primary" @click="select(record1)" size="small">选择</a-button>
      </span>
    </s-table>
  </a-modal>
</template>

<script>
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
import { STable, Ellipsis } from '@/components'
import { getAdminUser } from '@/api/user'
const columns = [
  {
    title: 'ID',
    dataIndex: 'id'
  },
  {
    title: '用户信息',
    dataIndex: 'nickname',
    scopedSlots: { customRender: 'baseinfo' },
    width: 200
  },
  {
    title: '会员等级',
    dataIndex: 'l_name'
  },
  {
    title: '绑定手机号',
    dataIndex: 'binding'
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '150px',
    scopedSlots: { customRender: 'action' }
  }
]

export default {
  name: 'UserList',
  components: {
    STable,
    Ellipsis
  },
  props: {
    queryParam: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    this.columns = columns
    return {
      locale: zhCN,
      // 会员列表
      roleList: [],
      visible: false,

      queryParamSelect: {},
      loadData: parameter => {
        Object.assign(parameter, this.queryParam)
        parameter.is_admin = 1
        return getAdminUser(parameter).then(res => {
          this.roleList = res.data.level
          return res.data
        })
      },
      loadDataSelect: parameter => {
        Object.assign(parameter, this.queryParamSelect)
        parameter.is_admin = 0
        return getAdminUser(parameter).then(res => {
          this.roleList = res.data.level
          return res.data
        })
      }
    }
  },
  methods: {
    select(record1){
      this.visible = false
      this.$emit('select', record1)
    },

    showAdd() {
      this.visible = true
    },

    onPageSearch() {
      this.$nextTick(() => {
        this.$refs.table1.refresh()
      })
    }
  }
}
</script>

<style scoped lang="scss">
.flex {
  display: flex;

  .img {
    margin-right: 10px;
    img {
      width: 45px;
      height: 45px;
      border-radius: 5px;
    }
  }

  .txt {
    flex: 1;
    overflow: hidden;
  }
}
</style>
